# from flask import current_app,request,jsonify
from celery import shared_task
# from . import bilibili_app
# from Async import app_celery 
# import ToolBox as tb

@shared_task
def url_2_video():
    # cache_dir = current_app.config['CacheDir']
    data = request.get_json()
    video_url = data["video_url"]
    if "save_dir" in data:
        save_dir = data["save_dir"]
    else:
        save_dir = current_app.config['video_save_dir']
        print(f"current_app;{save_dir}")
    task = app_celery.send_task(
        'ToolBox.get_bilibili_video', 
        args=[video_url,save_dir,cache_dir])
    msg={'msg':"Success!",'code':200,"taskid":task.id} 
    return jsonify(msg)


@shared_task
def url_2_audio():
    cache_dir = current_app.config['CacheDir']
    data = request.get_json()
    audio_url = data["audio_url"]
    if "save_dir" in data:
        save_dir = data["save_dir"]
    else:
        save_dir = current_app.config['audio_save_dir']
        print(f"current_app;{save_dir}")
    # task = app_celery.send_task(
    #     'ToolBox.get_bilibili_audio', 
    #     args=[audio_url,save_dir,cache_dir])
    task = tb.get_bilibili_audio.delay(audio_url,save_dir,cache_dir)
    msg={'msg':"Success!",'code':200,"taskid":task.id} 
    return jsonify(msg)